<?php
class IndexApp extends CommonApp {
   
    public function indexAct(){

  //   	//设置
  //   	$result = My::alias2detail('config','home');
  //   	$this->assign('result',$result);

  //   	//友情链接
  //   	$url = My::alias2detail('config','url');
  //   	$this->assign('url',$url);
  //   	//新闻
  //   	$news_s = My::item2list('datas','news',array('pagesize'=>5,'publish'=>1,'order'=>'hot'));//5条
  //   	$news_b = My::item2list('datas','news',array('pagesize'=>20,'publish'=>1,'order'=>'hot'));//20条
		// $this->assign('news_b',$news_b);
		// $this->assign('news_s',$news_s);

		// //通知公告
		// $announ = My::item2list('datas','announ',array('pagesize'=>8,'publish'=>1,'order'=>'hot'));//8条
		// $this->assign('announ',$announ);

		// //优秀团队
		// $team = My::item2list('datas','team',array('pagesize'=>8,'publish'=>1,'order'=>'hot'));//8条
		// $this->assign('team',$team);

		// //优秀成果
		// $event = My::item2list('datas','event',array('pagesize'=>12,'publish'=>1,'order'=>'hot'));//12条
		// $this->assign('event',$event);

    	$result = $this->checkLogin();
        //搜索条件
//         $search['where'] = " `parent_id`='{$result['memberid']}' ";
//         //按申报时间
//         if(My::is_id(My::arr2var($_GET,'year'))){
//             $year = $_GET['year'];
//             $search['where'] .= "AND `year`='{$year}' ";
//         }else $search['where'] .= "AND `year`='".date("Y")."' ";
//         //缓存时间
//         $search['time'] = isset($_COOKIE['time']) ? $_COOKIE['time'] : strtotime(date("Y-m-d H:i:s"));
//         $project = My::getCache($search,array('pre'=>'student'));
//         if($project == ''){
//             $project = DB('project')->where($search['where'])->find();//专业
//             if($project){
//                 $project['params'] = My::decodeJson($project['params']);
//                 $project['members'] = My::decodeJson($project['members']);
//             }
//             $project['now_year'] = date("Y");
//             $project['years'] = DB('project')->where("parent_id = {$result['memberid']}")->group('year')->field('year')->select();
//             setcookie("time",$search['time'],null,'/');
//             My::setCache($search,$project,array('pre'=>'student'));
// //            echo '没缓存项目,在刷新下';
// //            exit();
//         }
//         $this->assign('project',$project);//项目信息
        $this->assign('result',$result);//账号信息
		$this->display();

    }

    public function alter_passwordAct(){

    	$this ->display();
    }

    public function alterAct(){
    	if($_POST){
    		$userid = My::arr2var($_SESSION,'member.memberid');
    		$result = DB('homeuser')->clear()->where("id={$userid}")->find();
    		//用户名
	        // if(!My::is_string($_POST['username'],array('c')))
	        //   	$this->ajaxReturn(300,array('message'=>'真实姓名填写有误！','name'=>'username'));
	        //旧密码判断
	        if(md5(md5($_POST['old_password'])) != $result['password'])
	        	$this->ajaxReturn(300,array('message'=>'与原始密码不一致！','name'=>'old_password'));
	        //新密码
	        if(!My::is_string($_POST['password']))
	        	$this->ajaxReturn(300,array('message'=>'密码填写有误！','name'=>'password'));
	        if($_POST['password'] != $_POST['password2'])
	        	$this->ajaxReturn(300,array('message'=>'两次密码输入不一致！','name'=>'password2'));
	        $_POST['password'] = md5(md5($_POST['password']));
	        $_POST['editdate'] = $date = date("Y-m-d H:i:s");
	        $ok = DB('homeuser')->clear()->where("id={$userid}")->save($_POST);
	        if($ok>=0){
	        	unset($_SESSION['member']);  //unset用于销毁保存的session值
	        	$this->ajaxReturn(200,"密码修改成功，请重新登录！");
	        }else $this->ajaxReturn(300,"密码修改失败！");
    	}
    }
   
}